﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ClipPlayer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        //====================================================================================================================

        private void doEvents()
        {
            //http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.pushframe.aspx
            System.Windows.Threading.DispatcherFrame frame = new System.Windows.Threading.DispatcherFrame();
            System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new System.Windows.Threading.DispatcherOperationCallback(ExitFrame), frame);
            System.Windows.Threading.Dispatcher.PushFrame(frame);

            //Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate { }));
            //Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Threading.ThreadStart(() => System.Threading.Thread.Sleep(1))); 

            //System.Windows.Forms.Application.DoEvents();
        }
        public object ExitFrame(object f)
        {
            ((System.Windows.Threading.DispatcherFrame)f).Continue = false;
            return null;
        }
        //====================================================================================================================
        private void volumeToZero()
        {
            vlc.Volume = 0;
        }

        private void volumeToMax()
        {
            int n = 60;
            vlc.Volume = 10;
            System.Threading.Thread.Sleep(n); doEvents();
            vlc.Volume = 20;
            System.Threading.Thread.Sleep(n); doEvents();
            vlc.Volume = 40;
            System.Threading.Thread.Sleep(n); doEvents();
            vlc.Volume = 60;
            System.Threading.Thread.Sleep(n); doEvents();
            vlc.Volume = 80;
            System.Threading.Thread.Sleep(n); doEvents();
            //
            vlc.Volume = 100;
        }

        //====================================================================================================================
        private System.Windows.Threading.DispatcherTimer dt = new System.Windows.Threading.DispatcherTimer();
        void dt_Tick(object sender, EventArgs e)
        {
            dt.IsEnabled = false;
            //
            this.ShowInTaskbar = true;
            this.Activate();
            this.WindowState = System.Windows.WindowState.Normal;
            this.WindowStyle = System.Windows.WindowStyle.None;
            this.WindowState = System.Windows.WindowState.Maximized;
            //
        }

        public void EnterFullScreenMode()
        {
            dt.IsEnabled = true;
        }

        public void LeaveFullScreenMode()
        {
            this.Topmost = true;
            //
            this.WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
            this.WindowState = System.Windows.WindowState.Normal;
            //
            this.Topmost = false;
        }

        //====================================================================================================================
        public void SetButtonImage(Button b, string ResourceName)
        {
            Image i = new Image();
            i.Source = FindResource(ResourceName) as ImageSource;
            b.Content = i;
        }
        //====================================================================================================================
        private const string TrashBinName = ".Deleted";
        private void deleteFileSafe(string pathname)
        {
            string targetPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(pathname), TrashBinName);
            try
            {
                if (!System.IO.Directory.Exists(targetPath))
                {
                    System.IO.Directory.CreateDirectory(targetPath);
                }
                string targetName = System.IO.Path.Combine(targetPath, System.IO.Path.GetFileName(pathname));
                if(System.IO.File.Exists(targetName))System.IO.File.Delete(targetName);
                System.IO.File.Move(pathname, targetName);
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("[{0}]\n{1}", pathname, e.Message), "deleteFileSafe", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            //====================================================================================================================
        }
    }//class
}//namespace
